const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  mode : 'production',
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: { 
    rules: [
      {
        test: /\.png|\.jpe?g|\.gif|\.svg|\.ttf|\.eot|\.woff2|\.woff|\.mp4$/,
        type: 'asset/resource',
        generator: {
          filename: 'img/[name].[hash:8][ext][query]',
        },
      },
      {
        test: /\.(css|sass|scss)$/,
        use: [{
          loader : MiniCssExtractPlugin.loader,
        },'css-loader',{
          loader : 'sass-loader',
          options : {
            additionalData: (content, loaderContext) => {
              //const { resourcePath, rootContext } = loaderContext;
              //console.log(resourcePath);
              return content;
            },
          }
        }],
      },
      //{
        //test: /\.html|\.tpl$/i,
        //use : {
          //loader: 'html-withimg-loader',
          //options : {
            //sources : {
              //list : [
                //'...',
                //{
                  //tag: 'img',
                  //attribute: 'data-original',
                  //type: 'src',
                //}
              //]
            //}
          //}
        //}
      //},
    ]
  },
  plugins: [new MiniCssExtractPlugin({
    filename : 'css/[name].[contenthash:8].css'
  })],
};
